﻿/* ----------------------------------------------------------------------------
 * Copyright (c) Rob Ashton 2009
 *
 * This source code is subject to terms and conditions of the Microsoft Public 
 * License (Ms-PL).
 * 
 * By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 * 
 * To request a copy of the Microsoft Public License, send a request by email
 * to license@mvcex.com
 *
 * This notice must not be removed from this software.
 * ---------------------------------------------------------------------------- */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace MvcEx.Controllers
{
    /// <summary>
    /// This class derives from Controller and will be the base class from which all controllers are 
    /// built
    /// </summary>
    public partial class MvcExController : Controller
    {
        private IIocContainer mIocContainer;

        public MvcExController()
        {
            mIocContainer = null;
        }

        public MvcExController(IIocContainer container)
        {
            mIocContainer = container;
        }

        public void RegisterContainer(MvcExActionContainer container)
        {
            container.Initialize(this);
        }

        protected Object ResolveType(Type t)
        {
            if (mIocContainer != null)
            {
                return mIocContainer.GetInstance(t);
            }
            return null;
        }


        // TODO: Replace these with TT geneated methods
        public void CallUpdateModel<T>(T model) where T : class
        {
            this.UpdateModel<T>(model);
        }
        public void CallUpdateModel<T>(T model, String prefix) where T : class
        {
            this.UpdateModel<T>(model, prefix);
        }
    }
}
